from LogHandler import logger


def assertor(assert_list, response):
    """断言函数"""
    if type(assert_list) is not list:
        assert_list = [assert_list]

    for expr in assert_list:
        logger.info(f"开始断言：assert {expr}")
        try:
            if expr:
                exec(f"assert {expr}", {
                    "status_code": response.status_code,
                    "code": response.json().get("code", None),
                    "msg": response.text
                })
            logger.info(f"断言通过：assert {expr}")
        except AssertionError as e:
            logger.error(f"断言失败：{expr}不匹配实际值")
            raise e